﻿using FluentValidation;
using Mes.Application.Common;
using Mes.Application.DTO.Inputs.Quality;
using Mes.Application.DTO.Results.Quality;
using Mes.Application.Services.Quality;
using Mes.Domain.BoundedContext;
using Microsoft.AspNetCore.Mvc;

namespace Mes.Application.Web.Controllers.Quality
{
    public class SpcRuleController : ControllerBase
    {
        private readonly ISpcRuleService _spcRuleService;
        private readonly ILogger<SpcRuleController> _logger;

        /// <summary>
        /// Spc规则控制器
        /// </summary>
        /// <param name="spcRuleService">Spc规则服务</param>
        /// <param name="logger">日志服务</param>
        public SpcRuleController(ISpcRuleService spcRuleService, ILogger<SpcRuleController> logger)
        {
            _spcRuleService = spcRuleService;
            _logger = logger;
        }

        /// <summary>
        /// 查询Spc规则列表
        /// </summary>
        /// <returns></returns>
        [HttpGet("spcrules")]
        public async Task<ActionResult<ItemsResult<SpcRuleResult>>> GetSpcRulesAsync()
        {
            try
            {
                var response = await _spcRuleService.GetSpcRulesAsync();
                return Ok(response);
            }
            catch (CustomException ex)
            {
                _logger.LogError(ex.Message, ex);
                return BadRequest(ex.Message);
            }
        }
    }
}
